from flask import Flask, render_template, request
from flask import jsonify

app = Flask(__name__)
from flask_bootstrap import Bootstrap  # python3.x导入方式
# from flask.bootstrap import Bootstrap  #python2.x导入方式
from flask_bootstrap import Bootstrap
from services.ex_service import say_hello

bootstrap = Bootstrap(app)


# @app.route('/')
# def hello_world():
#     return 'Hello World!'


# 测试代码1
# @app.route('/')
# def test():
#     with app.app_context():
#         return render_template('indexAgg.html')


#测试代码2
@app.route('/')
def test():
    with app.app_context():
        return render_template('indexNew.html')


@app.route('/api/data', methods=['POST'])
def api_data():
    data = request.get_json()
    # 处理数据...
    return jsonify({'message': 'Data received'})


@app.route('/api/predict', methods=['POST'])
def predict():
    data = request.get_json()
    input_data = data.get('data')
    # 测试调用services层代码
    result1 = say_hello(input_data)
    print(result1)
    # 这里只是一个简单的示例，实际应用中需要根据输入数据进行复杂的计算或调用模型
    result = f"预测结果为：{input_data} 的反向是 {input_data[::-1]}"

    return jsonify({'result': result})


if __name__ == '__main__':
    # app.run() 默认5000
    app.run(debug=True, host="0.0.0.0", port=8086)
